import java.util.Arrays;

public class bubble {

    public static void main(String[] args) {

       int[] array = {3,6,2,3,5,1};
       bubbleSort(array);
        System.out.println(Arrays.toString(array));


    }

    private static void bubbleSort(int[] a) {

        for (int i = 0; i < a.length - 1; i++) {

            boolean swapped = false;

            for (int j = 0; j < a.length - 1 - i; j++) {

                if (a[j] > a[j+1]){
                    int t = a[j];
                    a[j] = a[j+1];
                    a[j+1] = t;
                    swapped = true;
                }

            }

            if (!swapped){
                break;
            }


        }
    }
}



